/*
* $Id: QueenBeeStore.java 292 2011-03-24 21:08:17Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.db;

import java.io.*;
import java.util.Date;

/**
 * Queen bee database
 * @author lexus
 */
public class QueenBeeStore extends DBStore
{
    /**
     * Container of queen bee records
     * @author lexus
     */
    public class QueenBeeRecord extends DBRecord
    {
//-----------------------------Breed of queen bee-------------------------------
        public static final int BREED_HYBRID = 0;
	public static final int BREED_ADAMII = 1;
	public static final int BREED_ADANSONII = 2;
	public static final int BREED_ANATOLICA = 3;
	public static final int BREED_ARMENIACA = 4;
	public static final int BREED_CAPENSIS = 5;
	public static final int BREED_CARNICA = 6;
	public static final int BREED_CARPATHICA = 7;
	public static final int BREED_CAUCASICA = 8;
	public static final int BREED_CECROPIA = 9;
	public static final int BREED_CYPRIA = 10;
	public static final int BREED_IBERIENSIS = 11;
	public static final int BREED_INTERMISSA = 11;
	public static final int BREED_JEMENITICA = 12;
	public static final int BREED_LAMARCKII = 13;
	public static final int BREED_LIGUSTICA = 14;
	public static final int BREED_LITOREA = 15;
	public static final int BREED_MACEDONICA = 16;
	public static final int BREED_MAJOR = 17;
	public static final int BREED_MEDA = 18;
	public static final int BREED_MELLIFERA = 19;
	public static final int BREED_MONTICOLA = 20;
	public static final int BREED_NUBICA = 21;
	public static final int BREED_POMONELLA = 22;
	public static final int BREED_REMIPES = 23;
	public static final int BREED_RUTTNERI = 24;
	public static final int BREED_SAHARIENSIS = 25;
	public static final int BREED_SANETA = 26;
	public static final int BREED_SCUTELLATA = 27;
	public static final int BREED_SICULA = 28;
	public static final int BREED_SOSSIMAI = 29;
	public static final int BREED_SYRIACA = 30;
	public static final int BREED_UNICOLOR = 31;
	public static final int BREED_FAREAST = 32;

        /** Identificator of queen bee */
        public int idQueenBee;
        /** Name queen bee */
        public String nameQueenBee;
        /** Description queen bee */
        public String description;
        /** Identificator of family */
        public int idFamily;
        /** Identificator of queen bee's parent */
        public int idParentQueenBee;
        /** Birthday queen bee */
        public Date date;
        /** Breed queen bee */
        public int breed;
        /** Fertility of queen bee */
        public String fert;
        /** Queen bee is dead or no */
        public boolean isDead;

        /**
         * Constructor
         */
        public QueenBeeRecord() {
            nameQueenBee = new String();
            description = new String();
            date = new Date();
            fert = new String();
        }

        /**
         * Gets byte array of record
         * @return byte array
         */
        public byte[] getData() {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                DataOutputStream dos = new DataOutputStream(baos);
                dos.writeInt(idQueenBee);
                dos.writeUTF(nameQueenBee);
                dos.writeUTF(description);
                dos.writeInt(idFamily);
                dos.writeInt(idParentQueenBee);
                dos.writeLong(date.getTime());
                dos.writeInt(breed);
                dos.writeUTF(fert);
                dos.writeBoolean(isDead);
                return baos.toByteArray();
            } catch (IOException ex) {}
            return null;
        }

        /**
         * Sets byte array record.
         * Array will be parsed and all fields of it will be filled
         * @param dis data input stream
         */
        public void setData(DataInputStream dis) throws IOException{
                idQueenBee = dis.readInt();
                nameQueenBee = dis.readUTF();
                description = dis.readUTF();
                idFamily = dis.readInt();
                idParentQueenBee = dis.readInt();
                date.setTime(dis.readLong());
                breed = dis.readInt();
                fert = dis.readUTF();
                isDead = dis.readBoolean();
        }
    }

    /**
     * Constructor
     */
    public QueenBeeStore() {
        super("db_queen_bee");
    }

    /**
     * Gets new record
     * @return new record
     */
    public DBRecord getRecord() {
        return new QueenBeeRecord();
    }
}
